Visual Basic is safer than many programming languages, but it still has its share of traps for the unwary. The Bug Stoppers that follow summarize the guidelines for avoiding the traps that are discussed in this chapter.
 | BUG STOPPERS: Gotchas
|
|
| Watch precision in tests.
|
|
| Control float loops with while.
|
|
| Control float loops with integers.
|
|
| Control date loops with while loops or integers.
|
|
| Dont resize arrays or collections inside loops that access them.
|
|
| Watch for circular object references.
|
|
| Understand when forms load and unload.
|
|
| Initialize all values.
|
|
| Use every value you calculate or remove the calculation.
|
|
| Make sure functions always define their return values.
|
|
| Beware of using the syntax from other programming languages.
|
|
| Never use GoTo except for error handling or to simplify code.
|
|
| Never use GoTo to jump backwards in the code.
|
|
| Never use GoTo to jump into a loop.
|
|
| Exit in one place.
|
|
| Place all error-handler code together at the end of the routine.
|
|
| Use an Exit Sub statement before error handlers.
|
|
| Do not use IIF, use If Then Else instead.
|
|
| Watch for overflow and underflow.
|
|
| Watch for divide-by-0 errors.
|
|
| Use parentheses and data type conversion functions to control variable promotion.
|
|
| Avoid functions that return status codes, but check them when you use such a function.
|
|
| Use Len and LenB to determine variable sizes.
|
|
| Do not assume constant values will never change.
|